<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>重置密码</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/font-awesome.min.css">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css">
    <script type="text/javascript" src="/js/jquery-3.7.1.min.js"></script>
</head>
<body style="background-color: azure;">
    <h1 style="position: relative; left: 650px;">重置密码系统</h1>
    <em>重新录入信息进行密码重置</em>
    <div class="container-fluid">
        <div style="position: relative; left: 680px; top: 100px;">
            <button type="button" class="btn btn-success btn-lg" data-toggle="modal" data-target="#myModal" onclick="preAdd();">
                重置密码
            </button>
        </div>
        <!--学生信息模态框-->
        <div class="modal fade" tabindex="-1" role="dialog" id="myModal">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">学生信息</h4>
                    </div>
                    <div class="modal-body">
                        <form id="studentForm">
                            <div class="form-group" id="editId" style="display: none;">
                                <label for="id">编号</label>
                                <input type="text" class="form-control" id="id" name="id" placeholder="编号" readonly>
                            </div>
                            <div class="form-group">
                                <label for="no">学号</label>
                                <input type="text" class="form-control" id="no" name="no" placeholder="学号" required
                                       minlength="10" maxlength="10">
                            </div>
                            <div class="form-group">
                                <label for="name">姓名</label>
                                <input type="text" class="form-control" id="name" name="name" placeholder="姓名" required
                                       minlength="2" maxlength="10">
                            </div>
                            <div class="form-group">
                                <label for="sex">性别</label>
                                <select class="form-control" id="sex" name="sex">
                                    <option value="1">男</option>
                                    <option value="2">女</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="cno">所选课程号</label>
                                <select class="form-control" id="cno" name="cno">
                                    <option value="2001">数据库</option>
                                    <option value="2002">高数</option>
                                    <option value="2003">操作系统</option>
                                    <option value="2004">计算机网络</option>
                                    <option value="2005">Web开发</option>
                                    <option value="2006">数据结构</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="score">成绩</label>
                                <input type="text" class="form-control" id="score" name="score" placeholder="成绩" required
                                       range:[0,100]>
                            </div>
                            <div class="form-group">
                                <label for="password">密码</label>
                                <input type="password" class="form-control" id="password" name="password" placeholder="密码" required>
                            </div>
                            <div class="modal-footer">
                                <button type="submit" class="btn btn-primary" id="saveBtn">保存</button>
                            </div>
                        </form> <!--表单结束-->
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
    </div>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script src="/plugins/layui/layui.js"></script>
    <script src="/plugins/bootstraptable/bootstrap-table.min.js"></script>
    <script src="/plugins/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="/plugins/jqvalidate/jquery.validate.min.js"></script>
    <script src="/plugins/jqvalidate/localization/messages_zh.min.js"></script>
    <script type="text/javascript" src="/pagejs/student/newlist.js"></script>
    <script>
        $(document).ready(function() {
            // 首先解绑之前存在的事件处理
            $('#studentForm').off('submit').on('submit', function(event) {
                event.preventDefault(); // 防止表单的默认提交
                // 可以在这里添加AJAX请求来保存数据，下面是假设成功保存后的处理代码
                $.ajax({
                    url: '/webapi/student/add',
                    type: 'POST',
                    data: $(this).serialize(),
                    success: function(response) {
                        // 假设保存成功后跳转到登录页面
                        window.location.href = '/index.html';
                    },
                    error: function(xhr, status, error) {
                        // 处理错误情况
                        console.error("保存失败", status, error);
                    }
                });
            });
        });
    </script>
</body>
</html>
